package main

import (
	"encoding/json"
	"fmt"
)

type Project struct {
	ProjectId   string `json:"ProjectId"`
	ProjectName string `json:"ProjectName"`
	RegionName  string `json:"RegionName"`
	RegionId    string `json:"RegionId"`
	BizScene    string `json:"BizScene"`
	Index       int    `json:"Index"`
}

type Node struct {
	NodeId             string `json:"NodeId"`
	NodeName           string `json:"NodeName"`
	NodeOrder          int    `json:"NodeOrder"`
	NodeApproverEnname string `json:"NodeApproverEnname"`
	NodeApproverCnname string `json:"NodeApproverCnname"`
	Status             int    `json:"Status"`
}

type Process struct {
	ProjectId   string `json:"project_id"`
	ProjectName string `json:"project_name"`
	RegionName  string `json:"region_name"`
	RegionId    string `json:"region_id"`
	BizScene    string `json:"biz_scene"`
	Index       int    `json:"index"`
	NodeList    []Node `json:"node_list"`
}

func main3() {
	// JSON input data
	inputJSON := `[{"ProjectId":"38d97f94-2aac-4cd0-8ee8-2a536d13f57c","ProjectName":"大铲湾企鹅公寓05项目","RegionName":"深圳","RegionId":"eb557454-acc7-477b-810c-67168f61344d","BizScene":"Price","Index":0,"NodeId":"f614f2f1-8bf0-4ac3-a8b6-9abaed9484c3","NodeName":"业务leader审批","NodeOrder":1,"NodeApproverEnname":"boneyxiang","NodeApproverCnname":"向阳","Status":1},{"ProjectId":"38d97f94-2aac-4cd0-8ee8-2a536d13f57c","ProjectName":"大铲湾企鹅公寓05项目","RegionName":"深圳","RegionId":"eb557454-acc7-477b-810c-67168f61344d","BizScene":"Price","Index":0,"NodeId":"7b87c2aa-afb3-4466-b97c-bf507c35660f","NodeName":"财管leader审批","NodeOrder":2,"NodeApproverEnname":"jeremyyou","NodeApproverCnname":"游俊杰","Status":1}]`

	// Unmarshal JSON input into slice of Project
	var projects []Project
	err := json.Unmarshal([]byte(inputJSON), &projects)
	if err != nil {
		fmt.Println("Error unmarshaling JSON:", err)
		return
	}

	// Process data and create slice of Process
	var processes []Process
	for _, project := range projects {
		process := Process{
			ProjectId:   project.ProjectId,
			ProjectName: project.ProjectName,
			RegionName:  project.RegionName,
			RegionId:    project.RegionId,
			BizScene:    project.BizScene,
			Index:       project.Index + 1, // Adjust index to start from 1
		}

		// Assuming nodes are grouped by ProjectId and ProjectName for simplicity
		// In real-world scenario, you might need additional logic to group nodes
		//process.NodeList = append(process.NodeList, Node{
		//	NodeId:             project.NodeId,
		//	NodeName:           project.NodeName,
		//	NodeOrder:          project.NodeOrder,
		//	NodeApproverEnname: project.NodeApproverEnname,
		//	NodeApproverCnname: project.NodeApproverCnname,
		//	Status:             project.Status,
		//})

		processes = append(processes, process)
	}

	// Marshal the slice of Process into JSON
	outputJSON, err := json.MarshalIndent(processes, "", "  ")
	if err != nil {
		fmt.Println("Error marshaling to JSON:", err)
		return
	}

	// Print the output JSON
	fmt.Println(string(outputJSON))
}

// 查看数组是否包含某个元素
func main() {
	list := []string{"hello", "kitty"}
	for _, item := range list {
		fmt.Println(item)

	}

	//kkk, dd := InArray(list, "kitty")
	//fmt.Println(kkk, dd)

}

func FindInSlice(slice []string, val string) (int, bool) {
	for i, item := range slice {
		if item == val {
			return i, true
		}
	}
	return -1, false
}
